package com.hk.shop.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hk.shop.base.service.BaseServiceImpl;
import com.hk.shop.dao.AdminDao;
import com.hk.shop.dao.UserDao;
import com.hk.shop.model.Admin;
import com.hk.shop.model.User;
import com.hk.shop.service.AdminService;

@Transactional
@Service("adminService")
public class AdminServiceImpl extends BaseServiceImpl<Admin, Integer> implements AdminService {

	@Resource
	private AdminDao adminDao;
	@Resource
	private UserDao userDao;
	
	@Override
	public void updateUser(User user) {
		userDao.update(user);
	}

	@Override
	public Admin checkUser(Admin adminUser) {
		return adminDao.findByAdminnameAndPassword(
				adminUser.getUsername(), adminUser.getPassword());
	}

	@Override
	public void deleteUser(Integer uid) {
		userDao.delete(userDao.get(uid));
	}

	@Override
	public List<User> findUser(Integer pageSize) {
//		Page<User> page =  new Page<User>();
//		PageInfo info = new PageInfo();
//		info.setPageSize(pageSize);
		return userDao.findAll(pageSize);
	}

	@Override
	public Long countUser() {
		Long count = userDao.countUser();
		return (count % 20 == 0 ? (count / 20) : (count / 20 + 1));
	}

	@Override
	public User findUserByUid(Integer uid) {
		return userDao.findOne(uid);
	}

	
}
